package java_0334_SmallChangeSys;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        String key = "";

        String details = "---------零钱通明细----------";
        double money = 0;
        double balance = 0;
        Date date = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");//用于日期格式化

        //4.消费
        String note = "";
        do {

            System.out.println("===========零钱通菜单=========");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.收益入账");
            System.out.println("\t\t\t3.消费");
            System.out.println("\t\t\t4.退   出");

            System.out.println("请选择（1~4）");
            key = scanner.next();


        switch (key){
            case "1":
                System.out.println(details);
                break;
            case "2":
                System.out.println("2.收益入账金额：");
                money = scanner.nextDouble();
                balance += money;
                date= new Date();
                details += "\n收益入账\t+"+money + "\t"+sdf.format(date)+"\t"+balance;
                break;
            case "3":
                System.out.println("3.消费金额");
                money = scanner.nextDouble();
                System.out.println("消费说明：");
                note = scanner.next();
                balance -= money;
                details += "\n" + note + "\t-" + money + "\t" + sdf.format(date) + "\t" + balance;
                break;
            case "4":
                //（1）定义一个变量choic,接受用户的输入
                //(2)使用while+break,来处理接受到的输入是否为y或者n
                //(3）退出while后，再判断choice是y还是n

                String choice = "";
                while (true){
                    System.out.println("你确定要退出吗？y/n");
                    choice = scanner.next();
                    if (choice.equals("y") || choice.equals("n")){
                        break;
                    }
                }


                if (choice.equals("y")){
                    loop = false;
                }
                break;

            default:
                System.out.println("选择有误，请重新选择");
        }

        }while(loop);
    }
}
